import { createStore, applyMiddleware, compose } from "redux";
// import thunk from "redux-thunk";
import api from '../middleware/api';
import rootReducer from '../reducers';
// const store = createStore(
//   rootReducer
//   // applyMiddleware(thunk)
// );
const composeEnhancers = typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
  ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
  : compose;
const configureStore = (preloadedState) => {
  const store = createStore(
    rootReducer,
    preloadedState,
    composeEnhancers(
      applyMiddleware(api),
      // applyMiddleware(api, thunk),
      // monitorReducerEnhancer,
    ),
  );

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('../reducers', () => {
      store.replaceReducer(rootReducer);
    });
  }

  return store;
};

export default configureStore;
